package cn.qf.web;

import cn.qf.convert.MyConvert;
import cn.qf.pojo.User;
import cn.qf.service.UserService;
import cn.qf.service.impl.UserServiceImpl;
import org.apache.commons.beanutils.ConvertUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.Map;

public class UpdateUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
        //解决post提交乱码
        req.setCharacterEncoding("utf-8");
        //单独获取uid
        String uid=req.getParameter("uuid");
        //因为接收所有单个参数麻烦（request,getparameter()）,所以将所有参数放在map中
        Map<String,String[]> map=req.getParameterMap();
        //创建User对对象
        User user=new User();
        /*自定义日期转换
        * 转换器：converuils的静态方法public clazz void register (Converter converter,Class clazz)
        * */
        ConvertUtils.register(new MyConvert(), Date.class);

        //调用业务接口
        UserService userService=new UserServiceImpl();
        userService.updateUser(user);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
